<?php
header('Content-Type: text/xml; charset=utf-8');
require_once('includes/includes.php');
$dir = '../songs';
#$dir = '../Kathamangal';
$fileArray = $GENOBJ->getFileList($dir, true, false, BASE_URL);
$finalArray = Array();
foreach ($fileArray as $_key => $_files) {
    if (array_key_exists($_files['dir'], $finalArray) && ($_files['type'] == 'file')) {
        $finalArray[$_files['dir']][$_key] = $_files;
    } else {
        if ($_files['type'] == 'file') {
            $finalArray[$_files['dir']][$_key] = $_files;
        }
    }
}

$XML = "";
$FOLDER = "";
foreach($finalArray  as $_key => $_value) {
	$folder_name =  preg_replace('/..\//', '', $_key, 1);
	$FOLDER .= "<folders><![CDATA[".$folder_name."]]></folders>";
}
foreach($finalArray  as $_key => $_value) {
	$folder_name =  preg_replace('/..\//', '', $_key, 1);
    $XML .= "<folder name='".$folder_name ."' >";
    foreach($_value as $_k => $_v) {
        $XML .= "<file><![CDATA[".$_v['url']."]]></file>";
    }
    $XML .= "</folder>";
}

$xmlHeader = "<?xml version='1.0' encoding='UTF-8' ?>";
$succNode = "<success><![CDATA[true]]></success>";
$rootStartNode = "<root>";
$rootStartNode = $rootStartNode.$FOLDER;
$rootEndNode = "</root>";
echo $xmlString = $xmlHeader . $rootStartNode . $XML . $rootEndNode;
exit;

?>
